<?php
namespace app\cls\sdk;
/**
 * 功能描述：签名
 * Class FoundaoVideoSDKSign
 */
class FoundaoVideoSDKSign {
    /**
     * 功能描述：序列化数据
     * @param $data
     * @return string
     */
    private static function serialize($data) {
        if (is_array($data)) {
            krsort($data);
            $str = "";
            foreach ($data as $key => $value) {
                $str .= ",{$key}=>" . self::serialize($value);
            }
            $ret = trim($str, ",");
        } else {
            $ret = $data;
        }
        return $ret;
    }

    /**
     * Sign constructor.
     * @param array $params
     * @param string $salt
     * @return mixed
     */
    public static function getSign($params, $salt = "") {
        $temStr = self::serialize($params);
        //3.把所有字符串全部转换成大写
        $upperStr = strtoupper($temStr);
        //4.加盐值加密，此处采用MD5加密
        return md5(substr(md5($upperStr . $salt), 0, 30));
    }
}